<template>
  <a-card :bordered="false">
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleTaskAdd" type="primary" icon="plus">新增</a-button>
      <a-button @click="loadData" type="primary" icon="search">查询</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table ref="table" size="middle" :scroll="{ x: true }" bordered rowKey="id" :columns="columns"
        :dataSource="dataSource" :pagination="ipagination" :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" class="j-table-force-nowrap"
        @change="handleTableChange">



        <span slot="action" slot-scope="text, record">
          <a @click="handleTaskEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleTaskDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.tid)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <collect-task-modal ref="modalForm" @ok="modalFormOk"></collect-task-modal>
    <c-s-task-sql-modal ref="confForm" @ok="modalFormOk"></c-s-task-sql-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin.js'
import CollectTaskModal from './modules/CollectTaskModal'
import CSTaskSqlModal from './modules/CSTaskSqlModal'

export default {
  name: 'CollectTaskList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    CollectTaskModal,
    CSTaskSqlModal
  },
  data() {
    return {
      description: '同步任务表管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '任务名称',
          align: "center",
          dataIndex: 'taskName'
        },
        {
          title: '任务执行的cron表达式',
          align: "center",
          dataIndex: 'taskCron'
        },
        {
          title: '任务状态 0暂停  1执行 2删除',
          align: "center",
          dataIndex: 'taskState',
          customRender: function (text) {
            if (text === 'stop') {
              return '暂停'
            } else if (text === 'running') {
              return '执行中'
            } else {
              return '未知'
            }
          }
        },
        {
          title: '任务描述',
          align: "center",
          dataIndex: 'taskDesc'
        },
        {
          title: '任务的下一次执行时间',
          align: "center",
          dataIndex: 'taskNextTime',
          customRender: function (text) {
            return !text ? "" : text
          }
        },
        {
          title: '任务的同步方式 select   log',
          align: "center",
          dataIndex: 'collectType'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/dcloud-platform/api/task/v1/list",
        delete: "/dcloud-platform/api/task/v1/delete",
        deleteBatch: "/dcloud-platform/api/task/v1/deleteBatch",
        exportXlsUrl: "/dcloud-platform/api/task/v1/exportXls",
        importExcelUrl: "/dcloud-platform/api/task/v1/importExcel",

      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'int', value: 'tid', text: '主键', dictCode: '' })
      fieldList.push({ type: 'string', value: 'taskName', text: '任务名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'taskCron', text: '任务执行的cron表达式', dictCode: '' })
      fieldList.push({ type: 'string', value: 'taskState', text: '任务状态 0暂停  1执行 2删除', dictCode: '' })
      fieldList.push({ type: 'string', value: 'taskDesc', text: '任务描述', dictCode: '' })
      fieldList.push({ type: 'date', value: 'taskNextTime', text: '任务的下一次执行时间' })
      fieldList.push({ type: 'string', value: 'syncType', text: '任务的同步方式 select   log', dictCode: '' })
      this.superFieldList = fieldList
    },
    handleTaskDetail: function (record) {
      this.$refs.confForm.showInfo(record)
      this.$refs.confForm.title = '详情'
      this.$refs.confForm.disableSubmit = true;
    },
    handleTaskEdit: function (record) {
      this.$refs.confForm.edit(record)
      this.$refs.confForm.title = '编辑'
    },
    handleTaskAdd: function (record) {
      this.$refs.confForm.add()
      this.$refs.confForm.title = '新增'
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>